﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace GMS.BIZ
{
    public class Paper
    {
        #region Property
        private string studentID;
        public string StudentID
        {
            get { return studentID; }
            //set { studentID = value; }
        }
        private string teacherID;
        public string TeacherID
        {
            get { return teacherID; }
            //set { teacherID = value; }
        }
        private string graduateYear;
        public string GraduateYear
        {
            get { return graduateYear; }
            //set { graduateYear = value; }
        }
        private string paperTitle;
        public string PaperTitle
        {
            get { return paperTitle; }
            //set { paperTitle = value; }
        }
        

        public PaperFile File1;
        public PaperFile File2;
        public PaperFile File3;
        public PaperFile File4;
        public PaperFile File5;
        public PaperFile File6;
        #endregion Property

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="studentID">学生学号</param>
        /// <param name="graduateYear">毕业年份</param>
        public Paper(string studentID,  string graduateYear)
        {
            this.studentID = studentID;
            this.graduateYear = graduateYear;

            //若该学生的PGuide信息不存在，则自动创建
            GMS.ORM.DAL.PGuide optPGuide = new GMS.ORM.DAL.PGuide();
            if (!optPGuide.Exists(this.studentID, this.graduateYear))
            {
                GMS.ORM.Model.PGuide newPGuide = new GMS.ORM.Model.PGuide();
                newPGuide.std_id = this.studentID;
                newPGuide.gyear = this.graduateYear;
                newPGuide.doc1 = 0;
                newPGuide.doc2 = 0;
                newPGuide.doc3 = 0;
                newPGuide.doc4 = 0;
                newPGuide.doc5 = 0;
                newPGuide.doc6 = 0;
                newPGuide.doc1id = 0;
                newPGuide.doc2id = 0;
                newPGuide.doc3id = 0;
                newPGuide.doc4id = 0;
                newPGuide.doc5id = 0;
                newPGuide.doc6id = 0;
                bool ok = optPGuide.Add(newPGuide);
            }

            //获得指导教师
            this.teacherID = optPGuide.GetModel(this.studentID, this.graduateYear).tch_id.ToString();

            //为PaperFile初始化
            PaperFile file1 = new PaperFile(1, this.studentID, this.teacherID);
            PaperFile file2 = new PaperFile(2, this.studentID, this.teacherID);
            PaperFile file3 = new PaperFile(3, this.studentID, this.teacherID);
            PaperFile file4 = new PaperFile(4, this.studentID, this.teacherID);
            PaperFile file5 = new PaperFile(5, this.studentID, this.teacherID);
            PaperFile file6 = new PaperFile(6, this.studentID, this.teacherID);
            this.File1 = file1;
            this.File2 = file2;
            this.File3 = file3;
            this.File4 = file4;
            this.File5 = file5;
            this.File6 = file6;

            //获得该学生的论文题目
            this.paperTitle = optPGuide.GetModel(this.studentID, this.graduateYear).papertitle;
        }

        /// <summary>
        /// 获得毕业论文状态
        /// </summary>
        public PaperInfo GetPaperInfo()
        {
            GMS.ORM.Model.PGuide myPGuide = new GMS.ORM.Model.PGuide();
            GMS.ORM.DAL.PGuide optPGuide = new GMS.ORM.DAL.PGuide();
            myPGuide = optPGuide.GetModel(this.studentID, this.graduateYear);

            PaperInfo returnPaperInfo = new PaperInfo();
            returnPaperInfo.Doc1file = myPGuide.doc1id;
            returnPaperInfo.Doc2file = myPGuide.doc2id;
            returnPaperInfo.Doc3file = myPGuide.doc3id;
            returnPaperInfo.Doc4file = myPGuide.doc4id;
            returnPaperInfo.Doc5file = myPGuide.doc5id;
            returnPaperInfo.Doc6file = myPGuide.doc6id;
            returnPaperInfo.Doc1status = myPGuide.doc1;
            returnPaperInfo.Doc2status = myPGuide.doc2;
            returnPaperInfo.Doc3status = myPGuide.doc3;
            returnPaperInfo.Doc4status = myPGuide.doc4;
            returnPaperInfo.Doc5status = myPGuide.doc5;
            returnPaperInfo.Doc6status = myPGuide.doc6;

            return returnPaperInfo;            
        }

        /// <summary>
        /// 获得某个类别文档的状态
        /// </summary>
        /// <param name="style">类别：1－6</param>
        public int GetOneStatus(int style)
        {
            int? returnStatus;

            switch (style)
            {
                case 1: returnStatus = this.GetPaperInfo().Doc1status; break;
                case 2: returnStatus = this.GetPaperInfo().Doc2status; break;
                case 3: returnStatus = this.GetPaperInfo().Doc3status; break;
                case 4: returnStatus = this.GetPaperInfo().Doc4status; break;
                case 5: returnStatus = this.GetPaperInfo().Doc5status; break;
                case 6: returnStatus = this.GetPaperInfo().Doc6status; break;
                default: returnStatus = null; break;
            }
            if (returnStatus == null)
                return 0;
            return int.Parse(returnStatus.ToString());
        }
        /// <summary>
        /// 修改论文题目
        /// </summary>
        /// <param name="papertitle">论文题目</param>
        /// <returns></returns>
        public string SetPaperTitle(string papertitle)
        {
            GMS.ORM.Model.PGuide myPGuide= new GMS.ORM.Model.PGuide();
            GMS.ORM.DAL.PGuide optPGuide = new GMS.ORM.DAL.PGuide();

            myPGuide = optPGuide.GetModel(this.studentID,this.graduateYear);
            myPGuide.papertitle = papertitle;
            this.paperTitle = papertitle;
            bool ok = optPGuide.Update(myPGuide);
            if (!ok) return ErrorMessage.DBOptError;
            return ErrorMessage.OK;
        }
        /// <summary>
        /// 获取评论
        /// </summary>
        /// <param name="docid">论文ID</param>
        /// <returns></returns>
        public string GetComment(decimal docid)
        {
            GMS.ORM.Model.PFile myPFile = new GMS.ORM.Model.PFile();
            GMS.ORM.DAL.PFile optPFile = new GMS.ORM.DAL.PFile();
            myPFile = optPFile.GetModel(docid);
            return myPFile.comment;
        }
    }
}
